package com.itheima.controller;


import com.itheima.domain.FlashPromotionSession;
import com.itheima.manager.SmsFlashPromotionSessionManager;
import com.itheima.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {

    @Autowired
    SmsFlashPromotionSessionManager sessionManager;


    //获取全部场次
    @GetMapping("/list")
    public Result list(){
        return sessionManager.list();
    }

    //添加场次
    @PostMapping("/create")
    public Result create(@RequestBody FlashPromotionSession promotionSession){
        return sessionManager.create(promotionSession);
    }

    //获取全部可选场次及其数量
    @GetMapping("/selectList")
    public Result selectList(@RequestParam Integer flashPromotionId){
        return sessionManager.selectList(flashPromotionId);
    }

    //获取场次详情
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        return sessionManager.selectById(id);
    }

    //删除场次
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        return sessionManager.delete(id);
    }

    //修改启用状态
    @PostMapping("/update/status/{id}")
    public Result updateStatus(@PathVariable Integer id,@RequestParam(required = false) Integer status){
        return sessionManager.updateStatus(id,status);
    }

    //修改场次
    @PostMapping("/update/{id}")
    public Result updateById(@PathVariable Integer id,@RequestBody FlashPromotionSession promotionSession){
        return sessionManager.updateById(id,promotionSession);
    }
}
